home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / metamail / contrib / amiga / AmigaSrc / getfilename.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-05  |  995 b   |  41 lines

  1. /* Ask the user to name a file in a given format.
  2.  * The getfilename program will ask the user for the name of a
  3.  * file in the specified format, and will copy that file to the
  4.  * file-name given as the second argument.
  5.  *
  6.  * Usage:
  7.  *  getfilename format_name temp_file_name
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12.  
  13. main(argc, argv)
  14. int argc;
  15. char **argv;
  16. {
  17.     char lineBuf[200];
  18.     char command[250];
  19.     int i;
  20.  
  21.     if (argc != 3) {
  22.         fprintf(stderr, "Usage: %s format_name temp_file_name\n", argv[0]);
  23.         exit(10);
  24.     }
  25.  
  26.     printf("Enter the name of a file in '%s' format: ", argv[1]);
  27.     fgets(lineBuf, sizeof(lineBuf), stdin);
  28.     i = strlen(lineBuf);
  29.     if (i > 0 && lineBuf[i - 1] == '\n') {
  30.         lineBuf[i - 1] = 0;
  31.         i--;
  32.     }
  33.     if (i == 0 || access(lineBuf, 4)) {
  34.         fprintf(stderr, "%s: Unable to access file '%s'\n", argv[0], lineBuf);
  35.         exit(10);
  36.     }
  37.  
  38.     sprintf(command, "Copy %s %s", lineBuf, argv[2]);
  39.     exit(system(command));
  40. }
  41.